import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { BrowserRouter } from 'react-router-dom'

import {registerMicroApps, start, initGlobalState, MicroAppStateActions } from 'qiankun'

const state = {
  nickname: '最爱白菜吖吖'
}

const actions: MicroAppStateActions = initGlobalState(state)
actions.onGlobalStateChange((state, prev) => {
  console.log('qiankun-base onGlobalStateChange',state, prev)
})

setTimeout(()=>{
  actions.setGlobalState({...state, age: 19})
}, 2000)

actions.offGlobalStateChange()

registerMicroApps([
  {
    name: "mirco-app1",
    entry: "//localhost:3011",
    container: "#mirco-app1",
    activeRule: "/mirco-app1",
    props: {
      nickname: 'this is mirco-app1'
    }
  },
  {
    name: "mirco-app2",
    entry: "//localhost:3012",
    container: "#mirco-app2",
    activeRule: "/mirco-app2",
    props: {
      nickname: 'this is mirco-app2'
    }
  },
  {
    name: "mirco-app3",
    entry: "//localhost:3013",
    container: "#mirco-app3",
    activeRule: "/mirco-app3",
    props: {
      nickname: 'this is mirco-app3'
    }
  },
])

start()

const root = ReactDOM.createRoot(
  document.getElementById('root') as HTMLElement
);
root.render(
  <React.StrictMode>
    <BrowserRouter>
      <App />
    </BrowserRouter>
  </React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
